#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void tc(char ch[]);
void tx1(char ch[]);

int line_number = 1;       //输出行控制变量
int max_len;                //命令行参数数

int main(int argc,char *argv[])
{
    int i=0;
    int flag_tc = 0;
    int flag_tx = 0;
    max_len=argc-1;
    FILE *file=fopen(argv[3],"r");
    char ch[100];
    printf("%d  %d\n",max_len,line_number );

    if(fgets(ch,100,file)!=NULL){
        for(i ; i < max_len; i++) {
            if(strcmp(argv[i], "-tc")==0){
                flag_tc++;
            }
            if(strcmp(argv[i], "-tx1")==0){
                flag_tx++;
            }
        }

        printf("%d\n", flag_tc && flag_tx);

        if(flag_tc && flag_tx == 1){
            while (line_number != 0) {
                tc(ch);
                tx1(ch);
            }
        }
        //另一个功能
    }
    else printf("文件为空！\n");
    return 0;
}

void tc(char ch[])
{
    int i=0;

    printf("%07o",16*(line_number-1));

    for(i=(line_number-1)*16;i<line_number*16;i++)
    {
        if(ch[i]=='\n')
        {   i++;
            putchar(' ');
            printf("\\n");

        }
        if(ch[i]=='\0')
            break;

        putchar('  ');
        printf("%c", ch[i]);
        putchar(' ');

    }
    line_number++;
    printf("\n");
    }
    //printf("%07o",16*(j-1)+i);

void tx1(char ch[])
{
    int i;
    if(line_number % 2 == 0) {
        printf("       ");
        for(i=(line_number-1)*16;i<line_number*16;i++)
            {
                if(ch[i]=='\n')
                {   i++;
                    printf("%3x ",'\n');
                    line_number = 0;
                }
                if(ch[i]=='\0')
                break;
                printf("%3x ",ch[i]);
            }
    }
    line_number=0;
    printf("\n");
}
